<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>智慧生活 | 感谢有你</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="${rc.contextPath}/static/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="${rc.contextPath}/static/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="${rc.contextPath}/static/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="${rc.contextPath}/static/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="${rc.contextPath}/static/dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="${rc.contextPath}/static/plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="${rc.contextPath}/static/plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet" href="${rc.contextPath}/static/plugins/datepicker/datepicker3.css">
</head>
<!-- ADD THE CLASS fixed TO GET A FIXED HEADER AND SIDEBAR LAYOUT -->
<!-- the fixed layout is not compatible with sidebar-mini -->
<body class="hold-transition skin-blue fixed sidebar-mini">
<#include "/templete/templete.ftl"/>
<!-- Site wrapper -->
<div class="wrapper">
    <!-- 引入导航栏和菜单栏-->
    <@header/>
    <!-- =============================================== -->

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Hello World
                <small>来日纵是千千阙歌 飘于远方我路上</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li><a href="#">Layout</a></li>
                <li class="active">Fixed</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="callout callout-info">
                <h4>今天也是充满希望的一天哦!</h4>
                <div class="col-md-3 col-sm-4"><i class="fa fa-fw fa-calendar"></i>
                    <button type="button" style="width: 120px;display: inline-block;"
                            class="btn btn-primary btn-block btn-flat" id="signAttend">打卡签到
                    </button>
                    <!-- Small modal -->
                    <button class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">
                        记录你的心情
                    </button>
                </div>
                <br/>
            </div>
            <!-- /.box -->
            <!-- /.row -->

            <div class="row">
                <div class="col-xs-12">
                    <div class="box">

                        <!--  -->
                        <div class="box-header">
                            <h3 class="box-title">便纵有千种风情，更与何人说？</h3>

                            <div class="box-tools">
                                <div class="input-group input-group-sm" style="width: 150px;">
                                    <input type="text" name="table_search" class="form-control pull-right"
                                           placeholder="Search">

                                    <div class="input-group-btn">
                                        <button type="submit" class="btn btn-default"><i class="fa fa-search"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table id="attend_grid" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>日期</th>
                                    <th>心情</th>
                                    <th>留言</th>
                                    <th>城市</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
            </div>

            <!-- 弹窗-->
            <div class="modal fade bs-example-modal-sm example-modal" tabindex="-1" role="dialog"
                 aria-labelledby="mySmallModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span
                                    aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                            </button>
                            <h4 class="modal-title">树洞</h4>
                        </div>
                        <div class="modal-body">
                            <form id="newMessage" method="post">
                                <span>心情：</span> <input type="text" id="mood" name="mood"/>
                                <br/>
                                <span>留言：</span><input type="text" id="content" name="content"/>

                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal" id="messageDlgClose">关闭
                            </button>
                            <button type="button" class="btn btn-primary" id="messageSubmit">写好啦</button>
                        </div>
                    </div>
                </div>
            </div>


            <!-- /.col -->
        </section>
        <!-- /.content -->
    </div>

    <!-- =============================================== -->
    <!-- 引入底部-->
    <@footer/>
    <div class="control-sidebar-bg"></div>


</div>
<!-- ./wrapper -->
<!-- jQuery 2.2.3 -->
<script src="${rc.contextPath}/static/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${rc.contextPath}/static/bootstrap/js/bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="${rc.contextPath}/static/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${rc.contextPath}/static/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${rc.contextPath}/static/dist/js/app.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="${rc.contextPath}/static/dist/js/demo.js"></script>
<script src="${rc.contextPath}/static/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${rc.contextPath}/static/plugins/daterangepicker/moment.min.js"></script>
<script src="${rc.contextPath}/static/plugins/daterangepicker/daterangepicker.js"></script>
<script src="${rc.contextPath}/static/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script src="${rc.contextPath}/static/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${rc.contextPath}/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="${rc.contextPath}/static/dist/js/html5shiv.min.js"></script>
<script src="${rc.contextPath}/static/dist/js/respond.min.js"></script>
<!-- js-->
<script>
    $(function () {
        $("#signAttend").click(function () {
            $.ajax({
                url: "${rc.contextPath}/attend/signAttend",
                type: "post",
                dataType: 'html',
                date: {},
                success: function (data) {
                    if (data != null) {
                        alert(data);
                    } else {
                        alert("好像什么事都没有发生！");
                    }
                }
            });
        });

        $("#messageSubmit").click(function () {
            var mood = $("#mood").val();
            var content = $("#content").val();
            $.ajax({
                url: "${rc.contextPath}/home/saveMessage",
                type: "get",
                dataType: "",
                data: {"mood": mood, "content": content},
                success: function (data) {
                    if (data != "success") {
                        $("#messageDlgClose").click();
                        alert("好像发生了一些未知的事情呢！");
                        window.location.reload();
                    } else {
                        $("#messageDlgClose").click();
                        alert("树洞已经收到了你的消息哦!");
                        window.location.reload();
                    }
                }

            });
        });
        function formToJson(form) {
            var result = {};
            var fieldArray = $('#' + form).serializeArray();
            for (var i = 0; i < fieldArray.length; i++) {
                var field = fieldArray[i];
                if (field.name in result) {
                    result[field.name] += ',' + field.value;
                } else {
                    result[field.name] = field.value;
                }
            }
            return result;
        }

        Date.prototype.format = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1,                 //月份
                "d+": this.getDate(),                    //日
                "h+": this.getHours(),                   //小时
                "m+": this.getMinutes(),                 //分
                "s+": this.getSeconds(),                 //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds()             //毫秒
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            return fmt;
        };
        var table;
        var requestUrl = "${rc.contextPath}/home/queryMessageBordList";
        //提示信息
        $.fn.dataTable.ext.errMode = 'none';
        var lang = {
            "sProcessing": "处理中...",
            "sLengthMenu": "每页 _MENU_ 项",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
            "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页",
                "sJump": "跳转"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        };
        table = $("#attend_grid").dataTable({
            language: lang, //提示信息
            autoWidth: false, //禁用自动调整列宽
            stripeClasses: ["odd", "even"], //为奇偶行加上样式，兼容不支持CSS伪类的场合
            processing: true, //隐藏加载提示,自行处理
            serverSide: true, //启用服务器端分页
            searching: false, //禁用原生搜索
            orderMulti: false, //启用多列排序
            order: [], //取消默认排序查询,否则复选框一列会出现小箭头
            renderer: "bootstrap", //渲染样式：Bootstrap和jquery-ui
            columnDefs: [{
                "targets": 'nosort', //列的样式名
                "orderable": false //包含上样式名‘nosort'的禁止排序
            }],
            ajax: function (data, callback, settings) {
                var param = formToJson("");

                param.pageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                param.start = data.start;//开始的记录序号
                param.currentPage = (data.start / data.length) + 1;//当前页码
                $.ajax({
                    type: "GET",
                    url: requestUrl,
                    cache: false, //禁用缓存
                    data: param, //传入组装的参数
                    dataType: "json",
                    success: function (result) {
                        setTimeout(function () {
                            //封装返回数据
                            var returnData = {};
                            returnData.draw = data.startRow;//这里直接自行返回了draw计数器,应该由后台返回
                            returnData.recordsTotal = result.total;//返回数据全部记录
                            returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                            returnData.data = result.list;//返回的数据列表
                            //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
                            callback(returnData);
                        }, 200);
                    }
                });
            },
            columns: [
                {
                    "data": "seq",
                    render: function (data, type, full, row_col) {
                        return row_col.row + 1;
                    }
                },
                {
                    "data": "creatdate",
                    render: function (data, type, full) {
                        return new Date(data).format("yyyy-MM-dd hh:mm:ss");
                    }
                },
                {
                    "data": "mood",
                    render: function (data, type, full) {
                        return data;
                    }
                },
                {
                    "data": "content",
                    render: function (data, type, full) {
                        return data;
                    }
                },
                {
                    "data": "city",
                    render: function (data, type, full) {
                        return data;
                    }
                }
            ]
        }).api();   //此处需调用api()方法,否则返回的是JQuery对象而不是的API对象
        // js-end

    })
</script>
</body>
</html>
